#!/usr/bin/env bash
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 位置自检
if [ ! $(command -v yunzai) ];then
echo -e "$0: 脚本位置不在PATH环境，拒绝运行"
exit 1
fi
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#-_-# Yunzai项目管理脚本,详见yunzai --help
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 初始设置
# 是否检测终端尺寸
stty=false
# 脚本主目录
yzcfghome=$BASH_SANDBOX_ROOTDIR/etc/config
# 默认配置文件
defconfig=$yzcfghome/set.conf
# 远程主机登录信息
sshcfg=$yzcfghome/ssh.conf
# watch dog通行开关，true为开
dog=false
# 是否启用一言
yiyan=false
# 版本号
versions=3.9.1
# 更新时间
times=2024/04/17
# 是否启用交互插件，如果已安装的话
TUI=false
# Yunzai默认位置
yzpath=$HOME/Yunzai-Bot
# 项目名称，为管理器提供统一称呼和克隆路径
name=Yunzai-Bot
# 默认ffmpeg源地址
ffmpeg=https://gitee.com/yunxiyuan/yxybot/releases/download/ffmpeg
# 项目合集
indexURL=https://gitee.com/yhArcadia/Yunzai-Bot-plugins-index
# 项目索引数据
yunzai_app_data=$BASH_SANDBOX_ROOTDIR/etc/data/yunzai.install.list.json
# github代理加速
proxy=("ghproxy.net" "mirror.ghproxy.com" "github.moeyy.xyz")
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## 生成配置路径
[ ! -d $yzcfghome ]&&mkdir -p $yzcfghome
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 字体颜色
## 正常颜色
h01="\033[31m";   # 红
h02="\033[32m";   # 绿
h03="\033[36m";   # 蓝
h04="\033[33m";   # 黄
h07="\033[30m";   # 黑
h09="\033[35m";   # 紫
h10="\033[37m";   # 白
h11="\033[34m";   # 深蓝
## 加粗混色
h13="\033[1;30m"; # 深灰
h14="\033[1;31m"; # 深红
h15="\033[1;32m"; # 亮绿
h16="\033[1;33m"; # 亮黄
h17="\033[1;34m"; # 深蓝
h18="\033[1;35m"; # 暗紫
h19="\033[1;36m"; # 亮蓝
h20="\033[1;37m"; # 浅灰
## 特殊效果
h12="\033[4m";     # 下划线
h06="\033[0m";     # 取消效果
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 函数包
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 颜色
color(){ case $1 in num)[ -z $2 ]&&printf "\e[0m"&&exit 0;[[ $2 =~ ^(help|--help|h|-h)$ ]]&&echo "用法: color num [0-255]"&&exit 0;[[ $2 =~ ^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]&&printf "\e[38;5;%d;m" ${2}||echo -e "\033[0mcolor: 8-BitColor: “(Num:$2)”: 这不是一个合法的或不在范围内的色值";; rgb)[ -z $2 ]&&printf "\e[0m"&&exit 0;[[ $2 =~ ^(help|--help|h|-h)$ ]]&&echo "用法: color rgb [r,g,b]"&&exit 0;[[ $2 =~ ^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\,){2}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$ ]]&&printf "\e[38;2;%d;%d;%d;m" $(echo $2|sed "s/\,/\ /g")||echo -e "\033[0mcolor: TrueColor: “(R:$(echo $2|sed "s/\,/ G\:/;s/\,/ B\:/"))”: 这不是一个合法的RGB色值";; *|help)echo -e "用法: color [选项] [色值|help]\nnum -  8Bit 分辨率，色值范围：0 至 255，一个通道\nrgb - 24Bit 分辨率，三个通道的范围均为 0 至 255";esac;} #%用法：color help ，用于调制颜色
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 时间
gettime(){ getdate=$(date -d "0.435 second" +%H:%M:%S.%N);echo "${getdate: 0: -6}";} #%用于获取时间戳
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 输出前缀
king(){ echo -e "${h02}[小吉祥草王] ${h06}$@";} #%输出头_自定义
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
main(){ echo -e "[Yunzai][$(gettime)]";} #%输出头_元素，依赖 gettime 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
err(){ echo -e "${h01}$(main)[ERRO] ${h06}$@";} #%输出头_错误，依赖 main 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
log(){ echo -e "${h02}$(main)[INFO] ${h06}$@";} #%输出头_正常，依赖 main 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
warn(){ echo -e "${h04}$(main)[WARN] ${h06}$@";} #%输出头_警告，依赖 main 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
mark(){ echo -e "\e[38;2;127;127;127;m$(main)[MARK] ${h06}$@";} #%输出头_一般，依赖 main 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 计算器
cll(){ help="用法: cll [运算式]\n例如: cll \"(1+2)*3/4\"\n带有括号的运算式需带上单/双引号"; [ -z $1 ]&&echo -e "$help"&&exit 0;[[ $1 =~ ^(-)?(h|help)$ ]]&&echo $help&&exit 0;if [[ $1 == mcexp=* ]];then (fs_arg=${1##*=};if ! [[ $fs_arg =~ ^[0-9]+$ ]];then echo "非法的计算因素";exit;elif [[ $fs_arg -gt 24791 ]];then echo "超出游戏设定上限，不予计算";exit;fi;cll_mc_all_exp(){ if [[ $fs_arg -lt 17 ]];then awk "BEGIN{print $fs_arg^2+6*$fs_arg}";elif [[ $fs_arg -lt 32 ]];then awk "BEGIN{print 2.5*$fs_arg^2-40.5*$fs_arg+360}";elif [[ $fs_arg -gt 32 ]];then awk "BEGIN{print 4.5*$fs_arg^2-162.5*$fs_arg+2220}";fi;};cll_mc_level_exp(){ if [[ $fs_arg -lt 16 ]];then awk "BEGIN{print 2*$fs_arg+7}";elif [[ $fs_arg -lt 31 ]];then awk "BEGIN{print 5*$fs_arg-38}";elif [[ $fs_arg -gt 31 ]];then awk "BEGIN{print 9*$fs_arg-158}";fi;};mc_all_exp=$(cll_mc_all_exp $fs_arg);mc_level_exp=$(cll_mc_level_exp $fs_arg);fs_arg_1=$(cll $fs_arg+1);hw=35;echo -e "╭$(printf '%*s' $hw|sed 's/ /─/g')╮\n│$h19 经验值换算$(printf '%*s' $((hw - 11)))$h06│\n│ $(color num 7)经验等级为 $fs_arg 时:$(printf '%*s' $((hw - 16 - ${#fs_arg})))│\n│ 经验总量为 $mc_all_exp 点$(printf '%*s' $((hw - 15 - ${#mc_all_exp})))│\n│ 提升至 $fs_arg_1 级需要 $mc_level_exp 点经验$(printf '%*s' $((hw - 23 - ${#mc_level_exp} - ${#fs_arg_1})))│\n│ ${h17}Minecraft EXP$h06$(printf '%*s' $((hw - 14)))│\n╰$(printf '%*s' $hw|sed 's/ /─/g')╯";[[ $fs_arg = 24791 ]]&&echo -e "24791 为基岩版设定最大等级\n以上计算结果可能无效、\n无法证实或证实过程繁杂，\n且结果并无实际意义");else awk "BEGIN{print $1}" 2>/dev/null;fi;} #%计算器，详见 cll -help 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 计时器
s_time(){ start_time=$(date +%s.%N);} #%计时器，记录起始时间
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
e_time(){ end_time=$(date +%s.%N);printf %.2f $(cll ${end_time}-${start_time});} #%计时器，记录耗时，与 s_time 配合使用。(依赖 cll ）
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 检查软件包
ifapp(){ [ -z $(command -v $1) ]&&err "未安装${2:-$1}，无法满足运行要求"&&exit;} #%判断指定软件是否存在，用法：ifapp [软件包名] [软件名称]
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 朗读
word(){ help="用法: word [内容] [间隔: 默认0.1 | default：保持默认] [停顿：默认0.5 | false ：同步于间隔]\n间隔与停顿均为可选项，但停顿存在设置时必须同时设置间隔";if [ -z "$1" ]; then echo -e "$help";else [[ $1 =~ ^(-)?(h|help)$ ]]&&echo -e "$help"&&exit 0;local target="$1";local t0=${2:-0.1};[[ $2 =~ ^(Def|def|Default|default)$ || $2 =~ [A-Za-z]+ ]] && local t0=0.1;local t1=${3:-0.5};[[ ! $3 =~ ^[0-9]+(\.[0-9]+)?$ ]] && t1=0.5;local punctuation='!！?？,.;，。；-_）)］]》〉〕｝】」』〗>}•~～………：:、';for ((i=0; i<${#target}; i++ ));do local char="${target:$i:1}";if [[ "${punctuation}" == *"${char}"* ]]; then if [ ! -z "$3" ] && [[ "$3" == "false" ]]; then sleep "$t0";else sleep "$t1";fi;else if [[ "${char}" == "\n" ]]; then echo;sleep "$t0";else sleep "$t0";fi;fi;echo -ne "${char}";done;echo;fi;} #%动态文字朗读，详见 word -help 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 读取变量
setting(){ [ -z $1 ]&&exit;[ -z $2 ]&&exit;timeout 3 grep -E "^${1}=." $2 | sed "s/^${1}=//g";} #%简单读取配置文件，用法：setting [key] [文件]
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 检查路由连接
wlan(){ if [[ $(ip a | grep inet | wc -l) = 2 ]];then err "请连接网络"; exit 1; fi;} #%简单的检测网络连接
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 下载文件
wgets(){ [ -z $1 ]&&echo "用法: wgets [url] [path]"&&exit 0;wlan;yztmp=$yzhome/tmp&&rm -rf $yztmp&&mkdir -p $yztmp||err "wgets: Error..."&&exit 1;curl -L --retry 2 --connect-timeout 5 "$1";} #%下载文件，依赖 wlan 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 远程主机信息
addhost(){ mark "请填写IP地址或服务器网址\n(本机地址可填为 “localhost” 或 “127.0.0.1” ，用于连接termux)"&&read -p "IP address: " addip;mark "请填写设备 ${addip} 下的用户名"&&read -p "host User: " adduser;mark "请填写设备 ${addip} 下所用的端口"&&read -p "host: " host;mark "请填写设备 ${addip} 下用户 ${adduser} 的登录密码"&&read -sp "password: " addpasswd;ipv4="^([0-9]{1,3}\.){3}[0-9]{1,3}$";ipv6=$(echo "$addip" | tr -s ':' ' ' | wc -w),$(echo "$addip" | wc -c);if [[ $addip =~ $ipv4 ]]; then if [[ $addip == "127.0.0.1" || $addip == "192.168."* ]]; then sleep 0.001;else addips=$(echo $addip | sed "s/[0-9]/*/g");fi;fi;if [ $ipv6 == "8,40" ]; then addips=$(echo $ | sed "s/[0-9]/*/g");elif [ $ipv6 == "5,25" ]; then addips=$(echo $addip | sed "s/[0-9]/*/g");elif [ $addip == "localhost" ]; then addips=$addip;fi;echo;log "以下是你的登录信息:\nIP地址: $addips\n用户: $adduser\n密码: $(echo $addpasswd | sed "s/./*/g")"&&echo -e "# IP地址\nyz_ssh_address=$addip\n\n# 端口\nyz_ssh_host=$host\n\n# 用户名\nyz_ssh_user=$adduser\n\n# 密码\nyz_ssh_passwd=$addpasswd" > $sshcfg&&log "在终端上使用远程主机请输入命令\n${h02}yunzai run host [\"命令\"|留空]${h06}";} #%远程主机登录，作为依赖使用。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 代主机执行
host(){ ifapp ssh openssh;ifapp sshpass;if [ ! -f $sshcfg ];then addhost;else source $sshcfg&&sshpass -p $yz_ssh_passwd ssh $yz_ssh_user@$yz_ssh_address -p $yz_ssh_host "$@"||(echo -en "$(warn "检测到异常退出，退出原因是远程命令造成的吗？[Y/n] ")"&&read -n1 yesno;echo;if [[ ${yesno:-y} =~ (Y|y) ]];then warn "请检查服务端连接或进行验证连接"&&ssh $yz_ssh_user@$yz_ssh_address  -p $yz_ssh_host;elif [[ ${yesno:-y} =~ (N|n) ]];then exit 0;else exit 127;fi)fi;} #%远程执行命令，用法：host [命令]。（依赖 addhost ）
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 一言
yiyan(){ [ $(setting yiyan $defconfig) = "true" ]&&wlan&&hitokoto=$(curl -sLm3 https://v1.hitokoto.cn/?encode=json)&&hitokoto_one=$(printf "%s" ${hitokoto} | sed 's@,@\n@g' | grep 'hitokoto.*:' | awk -F '"' '{print $4}' | sed 's@^@“@' | sed 's@$@”@')&&hitokoto_author=$(printf "%s" ${hitokoto} | sed 's@,@\n@g' | grep -v 'commit_from' | grep 'from.*:' | awk -F '"' '{print $4}' | sed '/null,/d' | tr '\n' ' ')&&echo -e "${hitokoto_author}: ${hitokoto_one}";} #%一言，对网络要求较高。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 批处理替换
greps(){ trap "echo '退出'&&exit 0" 2;s_time;[ -z $1 ]&&echo '没有目标'&&exit;[ -z $2 ]&&echo '没有目的'&&exit;echo -e "greps批处理函数\nsed & grep\n当前位置：$(pwd)\n修改意图：$1 => $2\n按 Ctrl + C 退出";e=$(echo $1 | sed 's/\//\\\//g');g=$(echo $2 | sed 's/\//\\\//g');sed -i "s/$e/$g/g" $(grep $1 -rl ./*);log "处理完成，耗时$(e_time)秒";} #%批处理替换，作用域：当前目录下，用法：greps [目标] [目的]
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 检索未知位置的Yunzai
findyz(){ help="用法: findyz [根路径] [递归层数: 默认2]\n用于搜索Yunzai项目根目录";[ -z $(command -v node) ]&&echo 'findyz: 未安装nodejs'&&exit;[ -z $1 ]&&echo -e "$help"&&exit 0;[ $1 == "/" ]&&warn "findyz: 不得为根目录"&&exit 0;[[ $1 =~ ^(-)?(h|help)$ ]]&&echo -e "$help"&&exit 0;[ ! -z $2 ]&&[[ ! $2 =~ ^[0-9]+$ ]]&&echo 'findyz: 参数[2]: 必须为纯数字'&&exit;[ ! -z $2 ]&&[[ $2 -lt 1 || $2 -gt 16 ]]&&echo 'findyz: 参数[2]: 要求不低于1 且不高于16'&&exit;node -e "const findyz = (directory, depth = 2) => { if (depth === 0) { return [];}; const files = fs.readdirSync(directory);const results = [];for (const file of files) { const filePath = path.join(directory, file);if (fs.lstatSync(filePath).isDirectory()) { if (filePath.indexOf('node_modules') === -1) { results.push(...findyz(filePath, depth - 1));}} else { if (fs.lstatSync(filePath).isFile() && file.includes('package.json')) { const content = fs.readFileSync(filePath, 'utf-8');const json = JSON.parse(content);const name = json.name;if (name && name.includes('yunzai')) { results.push(filePath);}}}}return results;};const fds = results => { for (const result of results) { console.log(result.slice(0, -13));}};const main = async () => {const directory = '$1';const depth = '${2:-2}';const results = await findyz(directory, depth);fds(results);};main();";} #%搜索Yunzai路径，详见 findyz -help （依赖 node ）。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 安装软件
pacs(){ [[ ! $(cat /etc/issue) =~ 'Arch' ]]&&echo "仅支持Arch系发行版"&&exit;archlinux=("https://mirrors.ustc.edu.cn" "https://mirrors.tuna.tsinghua.edu.cn" "https://mirrors.bfsu.edu.cn" "https://mirrors.aliyun.com" "https://mirrors.tencent.com" "https://mirrors.163.com");reponame=("中国科学技术大学" "清华大学" "北京外国语大学" "阿里云" "腾讯云" "网易云");[ -z $1 ]&&err "未指定需安装的软件"&&echo -e "用法: pacs [软件名] [ 镜像源: 0-$((${#reponame[@]} - 1))]\n发送pacs --list查看镜像源"&&exit;[[ $1 =~ ^(-|--)?(l|ls|list)$ ]]&&repolength=${#archlinux[@]}&&log "以下是可选的archlinux镜像源, 序号为选项"&&for ((i=0; i<$repolength; i++));do echo -e "${i}.${reponame[${i}]}:";echo -e "${archlinux[${i}]}";done&&exit 0;mark "准备中...";archrepo=$2;[ -z $2 ]&&mark "没有选择镜像源，将选择默认: 0";archlinux=${archlinux[${archrepo: -0}]};reponame=${reponame[${archrepo: -0}]};log "选择镜像源: ${reponame}镜像站: ${archlinux}";archlinux=${archlinux}/archlinux/extra/os/x86_64/;log "选择分支: $archlinux";getweb=$(curl -sLm10 "$archlinux");apps_v="${1}-([0-9]{1,2}+\.[0-9]{1,2}+\.[0-9]{1,2}+\-[0-9]{1,2})-+(any|x86_64)+\.pkg.tar.zst";if [[ $getweb =~ $apps_v ]]; then apps_version=${BASH_REMATCH[1]};apps_aarch=${BASH_REMATCH[2]};log "Get $1 version: $apps_version , aarch: $apps_aarch";[[ ! $apps_aarch =~ ($(uname -m)|any) ]]&&echo -en "$(mark "这个包所适用的平台架构与本设备不符，确认继续拉取${1} v${apps_version}安装？")"||echo -en "$(mark "确认拉取${1} v${apps_version}安装？")";read -p "[Y/n] " -n1 yesno;echo;(if [[ ${yesno:-y} =~ (Y|y) ]];then pacman -U --noconfirm --needed ${archlinux}${1}-${apps_version}-${apps_aarch}.pkg.tar.zst || err "安装失败...";elif [[ ${yesno:-y} =~ (N|n) ]];then exit 0;fi);else err "安装失败...";fi;} #%使用国内源安装软件，依赖 pacman 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Yunzai进程管理
poss(){ if [ ! -z $(pgrep "[Yy]un(zai)?") ];then YzID="$(ps -p "$(pgrep "[Yy]un(zai)?")" -o comm=)";else YzID=Null;fi;if [ "${YzID}" == "Null" ];then mark "未检测到相关进程...";exit 0;fi;[[ $YzID =~ 'yunzai-menu' ]] && return 0;inpid="$(pidof "${YzID}")";pkill PM2;pkill node;pkill -2 $YzID >/dev/null;pkill redis-server;echo;warn "已强制终止相关进程\n$(mark)进程名: ${h02}${YzID}${h06}\n$(mark)进程号: ${h02}${inpid}${h06}";} #%Yunzai进程管理，脚本内部使用。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 搜索应用
yzapps(){ for i in $@;do command -v $i||echo Null;done;} #%搜索应用，脚本内部使用
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 搜索配置
yzset(){ for i in $@;do setting $i $defconfig||echo Null;done;} #%搜索脚本配置，脚本内部使用，依赖 setting 。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 生成配置文件
sets(){ echo -e "# 是否检测终端尺寸\nstty=$stty\n\n# WIFI_watch_dog\ndog=$dog\n\n# 使用yunzai时是否启用交互插件\nTUI=$TUI\n\n# 一言\nyiyan=true\n\n# Yunzai本地地址\nyzpath=$yzpath\n\n# 默认FFmpeg镜像源\nffmpeg=$ffmpeg\n\n# Yunzai相关项目合集\nindexURL=$indexURL" > $defconfig;} #%生成配置文件，脚本内部使用。
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 初始化
if [ ! -f $defconfig ];then
sets
fi
if [ -f $defconfig ];then
source $defconfig
name=$(printf $(echo $yzpath | awk -F/ '{print $NF}'))
fi
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## 识别框架自适应
YzApp=($(yzapps yunzai-list yunzai-menu yunzai-api yunzai-file yunzai-lite))
theplugin=${YzApp[0]}
thetui=${YzApp[1]}
theapi=${YzApp[2]}
thefile=${YzApp[3]}
thelite=${YzApp[4]}
if [ -f $yzpath/lib/bot.js ] && [ -f $yzpath/app.js ];then
isbot=true
else
isbot=false
fi
debian="apt install -y"
arch="pacman -Sy --noconfirm --needed"
centos="yum install -y"
dup="apt update"
aup="pacman -Syu"
cup="yum update"
issue=$(cat /etc/issue)
[[ $issue =~ 'Debian' ]]&&cmd=$debian&&up=$dup&&os=1
[[ $issue =~ 'Ubuntu' ]]&&cmd=$debian&&up=$dup&&os=1
[[ $issue =~ 'Arch' ]]&&cmd=$arch&&up=$aup&&os=2
[[ $issue =~ 'Centos' ]]&&cmd=$centos&&up=$cup&&os=3
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
## 判断终端宽度
${stty:-false} && ! [[ $1 == set ]] && [[ $(tput cols) < 66 ]] && echo -e "终端界面过窄\n请调整终端宽度至\n66或以上" && exit
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 判断系统架构
case $(uname -m) in
aarch64)arm=arm64;;
aarch32)arm=arm32;;
x86_32)arm=x86;;
x86_64)arm=x64;;
*)arm=Null
esac
if [ $arm = arm32 ] || [ $arm = x86 ];then
wran "32位机型或发行版系统支持较少，不推荐使用"
exit 127
elif [ $arm = Null ];then
wran "未知的设备或发行版系统架构，无法使用"
exit 127
fi
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# 检查软件安装
ins(){ [ -z $1 ]&&echo '未指定要求检查的软件包'&&exit;if [ ! $(command -v $1) ];then log "正在安装: $1";if ! $cmd $1;then err "$1: 安装失败！";exit 1;fi;log "$1: 安装完成";else mark "$1: 软件已存在";fi;} #%检查软件安装，脚本及各插件内部使用
inss(){ [ -z $1 ]&&echo '未指定要求检查的软件包'&&exit;if [ ! $(command -v $1) ];then log "正在安装: $1";if ! $cmd $1;then err "$1: 安装失败！";exit 1;fi;log "$1: 安装完成";fi;} #%检查软件安装，脚本及各插件内部使用
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#### 主模块
if [ -z $1 ];then
if [ $TUI == true ] && [ -x $thetui ];then
yunzai-test
else
warn "请使用“yunzai --help”以了解使用方法"
exit 127
fi
else
case "$1" in
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-h|help|--help|-help)
echo -e \
"用法: yunzai [选项] [选项|行为] [行为] ...\n"\
"必选选项对长短选项同样适用，在某些情况下不可缺少行为目的\n"\
"           选项                            描述\n"\
" -l --list <plugin|js>             查看${name}安装的插件\n"\
" -O --occupy                       查看${name}占用空间\n"\
" -s --start                        启动${name}\n"\
" -i --install <选项>               详细用法请用[ -h ]参数\n"\
" -R --remove <名称>                卸载指定plugin|${name}\n"\
" -d --dev <名称>                   查询项目设定的值\n"\
" -r --run <名称>                   调用内置函数\n"\
" -S --set <选项>                   项目设置\n"\
" -p --plugin <名称>                执行插件[多此一举]\n"\
" -P --property                     打印设备信息\n"\
" -I --index                        项目资源索引页\n"\
" -h --help                         打印本帮助信息并退出\n"\
" -v --version                      打印版本并退出"
yiyan
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-s|start|--start|-start)
log "请稍等..."
mark "检查网络中..."
if [[ ! $(ip a | grep inet | wc -l) = 2 ]];then
log "WLAN已连接"
else
err "请连接网络"
exit 1
fi
if [ $dog = "true" ];then
if [[ $(($(ps -ef|grep x0x1x2x3x4x5x6x7x8x9|awk '{print $2}'|wc -l) - 1)) = 0 ]];then
yunzai x0x1x2x3x4x5x6x7x8x9 &
mark "WatchDog已启动"
fi
fi
process=$(pgrep "[Yy]un(zai)?")
if [[ ! -z $process && ! $(ps -p "$process" -o comm=) =~ 'yunzai-menu'  ]];then
poss
mark "已终止${name}的进程，如欲继续使用请重新执行启动命令"
exit
fi
if [ -d $yzpath ];then
  if [ $(command -v redis-server) ];then
  redis=$yzpath/config/config/redis.yaml
  redis_port=$(grep port: $redis | awk '{print $2}')
  redis-server --daemonize yes --save 900 1 --save 300 10 --port $redis_port --ignore-warnings ARM64-COW-BUG >/dev/null
  mark "redis已启动 端口: $redis_port"
  else
  err "redis未安装!"
  exit 1
  fi
  if [ ! $(command -v node) ];then
  err "nodejs未安装!"
  exit 1
  fi
cd $yzpath
cfg=$yzpath/config/config/qq.yaml
defcfg=$yzpath/config/default_config/qq.yaml
if [ -f $cfg ];then
bot=$(sed -n "$(sed '/platform:/=')p" $cfg | sed -e 's/platform: //g')
case "${bot}" in
1)from=Android_Phone;;
2)from=Android_Pad;;
3)from=Android_Watch;;
4)from=MacOS;;
5)from=iPad;;
6)from=Android;;
*)from=Null
esac
mark "${name}启动中，将尝试使用${from}协议登录..."
else
if [ -f $defcfg ];then
mark "未找到${cfg}，这可能是首次启动"
else
mark "${name}启动中..."
yiyan
fi
fi
export NODE_OPTIONS=--no-deprecation
node app
else
err "请确认$yzpath路径未改动或是否安装了${name}，亦或者是否正确安装/设定了${name}"
fi
unset NODE_OPTIONS
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-l|-ls|ls|--ls|list|--list|-list)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
if [ -z $2 ] 2> /dev/null;then
err "请在命令处一同输入<plugin>或<js>"
    else
    if [ $2 == plugin ] 2> /dev/null;then
    log "来自 $yzpath/plugins 的发现:"
    for i in `ls -d $yzpath/plugins/*/ | grep -v 'genshin\|system\|other\|example\|bin\|adapter'`;do
    dirname $(ls ${i}*.js 2>/dev/null | grep 'index.js') 2>/dev/null | awk -F/ '{print $NF}'
    done | while IFS= read -r line; do
    echo "$line"
    done
    elif [ $2 == "js" ] 2>/dev/null;then
    log "来自 $yzpath/plugins 的发现:"
    for i in `ls -d $yzpath/plugins/*/ | grep -v 'genshin\|system\|other\|adapter'`;do
    ls ${i}*.js 2>/dev/null | grep -v 'guoba.support.js\|index.js\|main.js'
    done | while IFS= read -r line; do
    echo "[$(basename $(dirname $line 2>/dev/null))][$(basename $line 2>/dev/null)]"
    done
    else
    err "请输入正确的参数"
    exit 0
    fi
  fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-O|occupy|--occupy|-occupy)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
  king "请稍等,正在统计${name}的空间占用..."
  sleep 0.5
s_time
  king "${name}的空间占用为${h02}$(du -sh $yzpath | sed -e "s/G/GB/;s/M/MB/;s/K/KB/;s/$yzpath//" 2>/dev/null)${h06}"
log "用时$(e_time)秒"
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
R|-R|remove|--remove|-remove|rm|-rm|--rm|uninstall)
if [ -z $2 ];then
err "请指定目标"
exit 1
fi
case $2 in
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-j|--jsfile|--js|--JavaScriptFile|--javascriptfile)
if [ -z $3 ];then
err "请指定目标"
exit 1
fi
if [ $(echo $3 | grep '.js') ];then
jsname=$3
else
jsname=${3}.js
fi
if [ -z $4 ];then
warn "未指定分组，将从默认分组(example)寻找js文件"
jsdir=example
else
jsdir=$4
fi
if [ ! -f $yzpath/plugins/$jsdir/$jsname ];then
err "未找到指定js文件($jsname)，试试换个分组？"
exit 1
fi
if rm $yzpath/plugins/$jsdir/${jsname};then
log "删除完成，祝你使用愉快"
else
err "删除失败，请重试！"
exit 1
fi;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-B|--B|-Bot|--Bot|--bot|-bot|Yunzai)
if [ $isbot = true ];then
htr=我同意并允许删除$name，我愿意承受所有后果
warn "这将删除整个${name}！包括已安装的所有plugin！"
warn "在删除前请输入：${h01}${htr}${h06}"
read -p '请输入: ' htr1
if  [ ${htr} == ${htr1} ];then
mark "正在删除..."
rm -rf $yzpath/ && mark "删除完成，祝你使用愉快" || err "删除失败" && exit 1
else
err "输入错误或不同意"
exit 1
fi
else
err "${name}: 项目不存在"
exit 1
fi;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*)
if [[ $2 =~ ^(example|genshin|other|system|adapter)$ ]];then
err "$2: 不允许删除"
exit 1
elif [ -d $yzpath/plugins/$2 ];then
warn "是否删除$2？"
read -p '[Y/n]: ' nt
case $nt in
N|n)
mark "已退出删除"
exit 0;;
Y|y)
mark "开始删除..."
s_time
if rm -rf $yzpath/plugins/$2/;then
log "删除完成，用时$(e_time)秒，祝你使用愉快"
else
err "删除失败"
exit 1
fi
;;
*)
if [ -z $nt ];then
nt=Null
fi
err "${nt}: 意料之外的选项"
exit 1
esac
else
if [ ${2: 0: 1} = '-' ];then
err "yunzai: rm: $2: 意外的选项"
else
shopt -s nocasematch
findplugin=($(ls $yzpath/plugins/ | grep -iw "$2"))
if [[ ${#findplugin[@]} = 1 ]];then
err "$2: 不存在的plugin\n你可能预想的目标：\n${h03}$findplugin${h06}"
else
err "$2: 不存在的plugin"
fi
fi
exit 1
fi
esac
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
i|-i|install|--install|-install)
if [ ! -f ${theplugin} ];then
err "未安装扩展库，拒绝运行"
exit 1
fi
wlan
if [ -z $2 ];then
err "请指定目标，欲知详细用法请使用命令:\n${h02}yunzai install help${h06}"
exit 1
fi
case $2 in
-h|--help|-help|help)
echo -e \
"用法: yunzai install [选项]\n"\
"此为yunzai的项目安装功能[install]\n"\
" -A --add           检索软件并安装\n"\
" -B --Bot           安装${name}\n"\
" -l --list          查看可安装的plugin\n"\
" -c --custom        从指定URL安装plugin|jsfile\n"\
" -m --multi         连续安装指定plugin\n"\
" -y --yes           跳过询问\n"\
" <名称>             安装指定plugin\n";;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-l|ls|-ls|--ls|list|-list|--list)
arr=($(yunzai-list --all))
arrn=($(yunzai-list --all-name))
prev_letter=""
for ((i=0; i<${#arr[@]}; i++)); do
_name_=${arr[$i]}
current_letter=$(echo "$_name_" | awk '{print substr($1, 1, 1)}')
[[ $i = 0 ]]&&echo -e \
"按[${h02}Q${h06}]键离开界面 按[${h02}↑${h06}][${h02}↓${h06}]键/鼠标滚轮/触屏上下滑动翻阅\n"\
"使用方法：yunzai install [插件名] ...\n"\
" $h02[@]$h06 共计$h02[${#arr[@]}]$h06个Plugin项目"
if [[ $current_letter =~ [a-zA-Z] ]]; then if [ "${current_letter^}" != "${prev_letter^}" ];then echo -e " $h16[${current_letter^}]──────────────────────────────────\n $h06 │";prev_letter="$current_letter";fi;else if [ -n "$prev_letter" ]; then echo -e " $h16[#]──────────────────────────────────$h06\n  │";prev_letter="";fi;fi
echo -e \
"  $([[ $(($i + 1)) != ${#arr[@]} ]]&&echo ├||echo └) 项目"\
"$h03[$((i + 1))]$h19 $_name_\n"\
"  $([[ $(($i + 1)) != ${#arr[@]} ]]&&echo │||echo " ")$([ $(($i + 1)) -gt 9 ]&&echo " ")      └$h02[#]$h09 名称: $h04${arrn[$i]}插件$h06\n $([[ $(($i + 1)) != ${#arr[@]} ]]&&echo " │")"
done | less -Rm;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-B|--B|-Bot|--Bot|--bot|-bot|Yunzai)
if [ ! $(command -v git) ];then
err "未安装git，已终止进程"
exit 1
fi
yunzai_search_list=($(yunzai-list -A))
[ -z $3 ]&&log "仓库中收录了以下项目:\n${yunzai_search_list[@]}\n使用 yunzai install Yunzai [项目名称] 以安装项目"&&exit 0
yunzai_search=($(yunzai-list -S $3))
[[ $yunzai_search == Null ]]&&err "不存在的项目"&&exit 1
[[ $yunzai_search == "这是彩蛋啦^_^" ]]&&log "这是彩蛋啦^_^"&&exit 0
if [ ! -d $HOME/${yunzai_search[1]} ];then
log "正在克隆${yunzai_search[1]}..."
s_time
git clone https://${yunzai_search[0]} $HOME/${yunzai_search[1]} && log "克隆完成，用时$(e_time)秒" || (err "来自${h03}${yunzai_search[0]}${h06}: 拉取失败" && exit)
else
warn "已存在${yunzai_search[1]}, 位于: $HOME/${yunzai_search[1]}"
exit 127
fi
if [ ! $(command -v node) ];then
err "未安装node，已终止进程"
exit 1
fi
if [ ! $(command -v pnpm) ];then
err "未安装pnpm，已终止进程"
exit 1
fi
if `jq ".[\"Bots\"][\"${yunzai_search[1]}\"] | has(\"command\")" $yunzai_app_data`;then
log "检索到项目预设命令，获取命令数据"
jq -r ".[\"Bots\"][\"${yunzai_search[1]}\"][\"command\"][]" $yunzai_app_data | while IFS= read -r line; do
    log "执行命令: $line"
    eval $line
done
fi
if [ ! -d $HOME/${yunzai_search[1]}/node_modules ];then
log "检测无modules，尝试安装"
s_time
pnpm install -P --prefix $HOME/${yunzai_search[1]} &&
log "node_modules 安装完成" || err "node_module 安装失败"
mark "任务用时$(e_time)秒"
fi
if `jq ".[\"Bots\"][\"${yunzai_search[1]}\"] | has(\"plugins\")" $yunzai_app_data`;then
log "检索到附加项，获取数据中"
jq -r ".[\"Bots\"][\"${yunzai_search[1]}\"][\"plugins\"][]" $yunzai_app_data | while IFS= read -r line; do
log "为 ${yunzai_search[1]} 安装插件: $line"
installPlugin=($(yunzai-list $line))
url=${installPlugin[0]}
plugin=${installPlugin[1]}
model=${installPlugin[2]}
if [ ! -d $HOME/${yunzai_search[1]}/plugins/${plugin} ];then
mark "准备克隆${plugin}..."
if [[ $url =~ ^github.* ]];then
log "这是一个github项目。"
url=${proxy[${xy: -0}]}/$url
log "使用代理: https://${proxy[${xy: -0}]}/"
fi
s_time
if ! git clone --depth=1 https://${url}.git $HOME/${yunzai_search[1]}/plugins/${plugin};then
err "${plugin}: 拉取失败"
exit 1
else
log "${plugin}: 克隆完成，用时$(e_time)秒"
fi
if [ ${model} = off ];then
mark "${plugin}: 该plugin无模块需要。"
elif [ ${model} = auto ];then
if [ -f $HOME/${yunzai_search[1]}/plugins/$plugin/package.json ];then
mark "${plugin}: package.json: 发现有独立模块需安装，执行中..."
s_time
if yes | pnpm i --prefix $HOME/${yunzai_search[1]}/plugins/$plugin/;then
log "${plugin}: 独立模块安装完成，用时$(e_time)秒"
else
err "${plugin}: 独立模块安装失败"
mark "正在删除 ${plugin} ..."
s_time
if rm -rf $HOME/${yunzai_search[1]}/plugins/$plugin/;then
log "删除完成，用时$(e_time)秒"
else
err "删除失败"
fi
exit 1
fi
else
mark "${plugin}: 该plugin无模块需要。"
fi
else
mark "${plugin}: 发现有附加模块需安装，推荐:${model}，执行中..."
s_time
if yes | pnpm install ${model} -w --prefix $HOME/${yunzai_search[1]};then
log "${model}: 安装完成，用时$(e_time)秒"
else
err "${model}: 安装失败，请检查项目是否支持开发者权限"
exit 1
fi
fi
else
warn "${plugin}: 该plugin已存在"
fi
done
fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-y)
if [ -z $3 ];then
yunzai install
else
if [ -z $4 ];then
yunzai install $3 -y
else
yunzai install $3 $4 -y
fi
fi;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
add|A|--A|-A|--add|-add)
mark "检查更新所有软件..."
$up
log "完成。\n$(mark)检查安装所需软件..."
ins git
ins curl
ins wget
ins pv
ins jq
ins yq
if [ ! $(command -v redis-server) ];then
log "正在安装: redis"
if ! $cmd redis;then
err "redis: 安装失败！"
exit 1
fi
log "redis: 安装完成"
else
mark "redis: 软件已存在"
fi
ins chromium
if [ ! $(command -v ffmpeg) ];then
log "正在安装: ffmpeg"
if [ $os = "2" ];then
$cmd ffmpeg
ffmpeg
else
if ! wget -c -O /usr/local/bin/ffmpeg ${ffmpeg}/ffmpeg-${arm};then
err "ffmpeg: 安装失败！请检查源地址！"
exit 1
fi
chmod 755 /usr/local/bin/ffmpeg
ffmpeg
fi
log "ffmpeg: 安装完成"
else
mark "ffmpeg: 软件已存在"
fi
if [ ! $(command -v node) ];then
log "正在安装: node"
if [ ! $os = "2" ];then
if ! curl -sL https://deb.nodesource.com/setup_21.x | bash;then
err "软件源设置失败"
exit 1
fi
fi
if ! $cmd nodejs;then
err "node: 安装失败！"
exit 1
fi
log "node: 安装完成"
else
mark "node: 软件已存在"
fi
if [ ! $(command -v pnpm) ];then
log "正在安装: pnpm"
if [ $os = "2" ];then
if ! pacs pnpm;then
err "pnpm: 安装失败！"
exit 1
fi
else
if ! npm install pnpm -g;then
err "pnpm: 安装失败！"
exit 1
fi
fi
log "pnpm: 安装完成"
else
mark "pnpm: 软件已存在"
fi
case $os in
1)
if [ ! -d /usr/share/fonts/truetype/wqy ];then
log "正在安装所需字体库: 文泉驿微黑"
$cmd --force-yes --no-install-recommends fonts-wqy-microhei
$cmd ttf-wqy-microhei
log "文泉驿微黑: 已载入字体库"
else
mark "该字体已存在"
fi
;;
2)
if [ ! -d /usr/share/fonts/wenquanyi ];then
log "正在安装所需字体库: 文泉驿正黑"
$cmd wqy-bitmapfont wqy-zenhei ttf-arphic-ukai ttf-arphic-uming
log "文泉驿正黑: 已载入字体库"
else
mark "文泉驿正黑: 该字体已存在"
fi;;
3)
if [ ! -d /usr/share/fonts/truetype/chinese ];then
log "正在安装所需字体库: 中文"
$cmd fonts-chinese
$cmd fonts-chinese.noarch
$cmd epel-release
log "中文: 已载入字体库"
else
mark "中文: 该字体已存在"
fi;;
esac
if [ ! $(command -v ssh) ];then
log "正在安装: openssh"
if ! $cmd openssh;then
err "openssh: 安装失败！"
exit 1
fi
log "openssh: 安装完成"
else
mark "openssh: 软件已存在"
fi
ins sshpass
log "检查完成。";;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
multi|--multi|-multi|-m|m)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
if [ -z $3 ];then
err "请指定一个或以上目标"
exit 1
fi
if [ $3 = -y ] && [ -z $4 ];then
err "请指定一个或以上目标"
exit 1
fi
case $3 in
-y|yes|--yes|-yes)
yunzai install --multi $(echo ${@: 3} | sed 's/\-y//g') -y;;
*)
if [ ! ${!#} = -y  ]||[ ! ${!#} = -yes  ]||[ ! ${!#} = --yes  ]||[ ! ${!#} = yes  ];then
echo -e "${h03}${@: 3}${h06}"
mark "是否允许安装以上plugin?"
read -p "[Y/n]: " nt
case $nt in
N|n)
mark "已退出安装"
exit 0;;
Y|y)
log "开始安装...";;
*)
if [ -z $nt ];then
nt=Null
fi
err "${nt}: 意料之外的选项"
exit 1
esac
fi
    for mpsl in $(echo ${@: 3} | sed 's/\-y//g'); do
         yunzai install $mpsl -y
     done
   exit 0;;
esac
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-c|custom|--custom|-custom)
case $3 in
-y)
if [ -z $4 ];then
yunzai install -c
else
yunzai install -c $4 $5 -y
fi;;
*)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
if [ -z $3 ];then
err "请指定目标"
echo '用法: yunzai install custom [URL] [files] -y'
exit 0
fi
if [ ! ${!#} = -y ];then
log "是否继续执行?"
read -p "[Y/n]: " nt
case $nt in
N|n)
mark "已退出"
exit 0;;
Y|y)
mark "开始执行...";;
*)
if [ -z $nt ];then
nt=Null
fi
err "${nt}: 意料之外的选项"
exit 1
esac
fi
if [ ! $(command -v curl) ];then
echo -e "(err)未安装curl"
exit 1
fi
if [ ! $(command -v git) ];then
echo -e "(err)未安装git"
exit 1
fi
if [ ! $(command -v node) ];then
echo -e "(err)未安装node"
exit 1
fi
if [ ! $(command -v pnpm) ];then
echo -e "(err)未安装pnpm"
exit 1
fi
url=$3
mark "测试网址连通性..."
if [[ $url =~ ^github.* ]];then
log "这是一个github项目。"
url=${proxy[${xy: -0}]}/$url
log "使用代理: https://${proxy[${xy: -0}]}/"
fi
if [[ $(curl -s $url) =~ 你所访问的页面不存在 ]];then
err "连接异常: 404"
exit 1
elif [[ $(curl -s $url) =~ 您的访问受限 ]];then
err "连接异常: 403"
exit 1
fi
if [ ${url: 0-3} = ".js" ];then
mark "该链接可能是某一个后缀为“.js”的插件的源地址"
if [ $4 = '-y' ] && [ -z $5 ];then
mark "未指定js插件安装位置，将安装在默认分组（example）"
jsdir=example
else
jsdir=$4
fi
if [[ $3 = *\/blob\/* ]];then
jsurl=$(echo $url | sed 's/\/blob\//\/raw\//g')
mark "网址非源文件，已纠正为: \n${h12}${jsurl}${h06}"
else
jsurl=$url
fi
jsname=`echo $jsurl | awk -F/ '{print $NF}'`
newname=$(echo $jsname | sed 's/%/\\x/g')
if [ -f $yzpath/plugins/$jsdir/"$(echo -e $newname)" ];then
mark "$newname: 该插件已存在"
exit 127
fi
s_time
if wgets "$jsurl" > "$yzpath/plugins/example/$newname";then
#rm $newname
log "下载完成，已下载到: \n${h03}$yzpath/plugins/$jsdir/$newname${h06}   用时$(e_time)秒"
else
err "下载失败"
exit 1
fi
elif [ ${url: 0-4} = ".git" ];then
mark "该链接可能是某一个plugin的源地址"
pnames=(`echo $@ | sed 's/-y//g'`)
purls=$(printf $(echo $url | awk -F/ '{print $NF}'))
if [ -z $4 ];then
mark "未指定plugin名称，将从网址字段中截取可能的名称..."
pn=$(echo $purls | sed 's/.git//g')
log "可能的plugin名称: $pn"
else
pn=$4
fi
if [ -d $yzpath/plugins/$pn ];then
mark "$pn: 该plugin已存在"
exit 0
fi
mark "正在克隆: $pn"
s_time
if git clone --depth=1 $url $yzpath/plugins/$pn;then
log "$pn: 克隆完成，用时$(e_time)秒"
else
err "$pn: 克隆失败"
exit 1
fi
if [ -f $yzpath/plugins/$pn/package.json ];then
mark "$pn: 发现可安装的模块，尝试安装..."
s_time
if yes | pnpm i -P --prefix $yzpath/plugins/$pn;then
log "模块安装完成，用时$(e_time)秒"
else
err "模块安装失败"
exit
fi
fi
else
mark "无法识别的类型"
fi
unset pn purls pnames jsurl;;
esac
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
installPlugin=($(yunzai-list $2))
if [ ${installPlugin} = null ];then
err "$2: 该plugin未记录在库或不存在"
exit 1
fi
if [ ! ${!#} = -y ];then
mark "是否安装$2?"
read -p "[Y/n]: " nt
case $nt in
N|n)
log "已退出安装"
exit 0;;
Y|y)
mark "开始安装...";;
*)
if [ -z $nt ];then
nt=Null
fi
err "${nt}: 意料之外的选项"
exit 1
esac
fi
url=${installPlugin[0]}
plugin=${installPlugin[1]}
model=${installPlugin[2]}
if [ ! -d $yzpath/plugins/${plugin} ];then
mark "准备克隆${plugin}..."
if [[ $url =~ ^github.* ]];then
log "这是一个github项目。"
url=${proxy[${xy: -0}]}/$url
log "使用代理: https://${proxy[${xy: -0}]}/"
fi
s_time
if ! git clone --depth=1 https://${url}.git $yzpath/plugins/${plugin};then
err "${plugin}: 拉取失败"
exit 1
else
log "${plugin}: 克隆完成，用时$(e_time)秒"
fi
if [ ${model} = off ];then
mark "${plugin}: 该plugin无模块需要。"
elif [ ${model} = auto ];then
if [ -f $yzpath/plugins/$plugin/package.json ];then
mark "${plugin}: package.json: 发现有独立模块需安装，执行中..."
s_time
if yes | pnpm i --prefix $yzpath/plugins/$plugin/;then
log "${plugin}: 独立模块安装完成，用时$(e_time)秒"
else
err "${plugin}: 独立模块安装失败"
mark "正在删除 ${plugin} ..."
s_time
if rm -rf $yzpath/plugins/$plugin/;then
log "删除完成，用时$(e_time)秒"
else
err "删除失败"
fi
exit 1
fi
else
mark "${plugin}: 该plugin无模块需要。"
fi
else
mark "${plugin}: 发现有附加模块需安装，推荐:${model}，执行中..."
s_time
if yes | pnpm install ${model} -w --prefix $yzpath;then
log "${model}: 安装完成，用时$(e_time)秒"
else
err "${model}: 安装失败，请检查项目是否支持开发者权限"
exit 1
fi
fi
else
warn "${plugin}: 该plugin已存在"
fi
;;
esac
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-S|set|--set|-set)
if [ ! -f $defconfig ];then
err "找不到配置文件"
exit 1
fi
apex=0
if [ -z $2 ];then
echo -e "$h19##Setting##$h06\n$(sed "s/^/\\\033[32m/g;s/=/\\\033[36m=\\\033[33m/g;s/#/\\\033[1\;35m#/g;s/$/\\\033[0m/g" $defconfig)\n\n$h13位置: $defconfig$h06\n\n按[${h02}Q${h06}]键离开界面" | less -R
let apex++
else
for i in $(cat $defconfig|grep -o '.*='|tr -d "="); do
h=$(setting $i $defconfig | sed 's/\//\\\//g')
d=$(sed -n "/^$i/=" $defconfig)
r=$(echo $3 | sed 's/\//\\\//g')
if [ $2 == $i ];then
let apex++
if [ -z $3 ];then
setn=$2
log "当前$setn的设置项为${!setn}"
exit 1
fi
if [ $r == $h ];then
warn "$2: 重复的设置"
exit 127
else
if [[ ${!2} =~ ^(false|true)$ ]]&&[[ ! $3 =~ ^(false|true)$ ]];then
warn "$2: 新的设置并非布尔值"
mark "如有需求请修改：$h03${defconfig}$h06"
exit 0
elif [[ ! ${!2} =~ ^(false|true)$ ]]&&[[ $3 =~ ^(false|true)$ ]];then
warn "$2: 新的设置不得为布尔值"
mark "如有需求请修改：$h03${defconfig}$h06"
exit 0
fi
sed -i "${d}s/$h/$r/" $defconfig
log "已将$i的规则更新为$3"
exit 0
fi
fi
done
fi
if [ $apex == 0 ];then
err "$2: 未知的选项"
exit 1
fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-I|index|--index|-index)
if [ -f $sshcfg ];then
source $sshcfg
if [[ $yz_ssh_address == localhost ]]||[[ $($yz_ssh_address) == 127.0.0.1 ]];then
host am start $indexURL > /dev/null
else
mark "网址:\n${h03}${h12}${indexURL}${h06}"
fi
else
mark "网址:\n${h03}${h12}${indexURL}${h06}"
fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-d|dev|--dev|-dev)
[ -z $2 ]&&echo "空的输入"&&exit 127
dev=$2
if [[ -z "${!dev}" ]];then
echo -e "\"$2\": 找不到"
elif [ ! -z $3 ]&&[[ $3 == "notfound" ]];then
echo -e "${!dev}"
else
echo -e "\"$2\" 是 $h02\"${!dev}\"$h06"
fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-v|version|--version|-version)
#yunzai
case $2 in
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-vv)(
bin_path=($(echo $PATH | sed 's/\:/ /g'))
yzsearch=($(for ((i=0;i<${#bin_path[@]};i++));do ls ${bin_path[$i]} 2>/dev/null;done | grep -E 'yunzai*'))
echo -e \
"按[${h02}Q${h06}]键离开界面 按[${h02}↑${h06}][${h02}↓${h06}]键/鼠标滚轮/触屏上下滑动翻阅\n"\
"$h19## 共 $h16[${#yzsearch[@]}]$h19 个实例 ##\n"\
"$h16[U]"
yz_all_k=0
yz_all_f=0
for ((i=0;i<${#yzsearch[@]};i++));do
#yunzai
  yz_file_path=$(command -v ${yzsearch[$i]})
  yz_ver=$(setting versions $yz_file_path)
  yz_m=$(grep '^#-_-#' $yz_file_path | sed 's/^.*#-_-# //')
  yz_t=$(setting times $yz_file_path)
  yz_b=$(stat -c %s $yz_file_path)
  yz_k=$(cll $yz_b/1024)
  yz_all_k=$(cll ${yz_all_k}+${yz_k})
  yz_all_f=$(cll ${yz_all_f}+${yz_f})
  yz_f=$(grep -o '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*(){' $yz_file_path | tr -d '(){}' | wc -w)
  yz_p=$(sed -n '1p' $yz_file_path)
  yz_s=(${yz_p##*/})
  yz_l=($(ls -l $(command -v ${yzsearch[$i]})))
[ ${yz_s[0]} = env ]&&yz_s=${yz_s[1]}
  echo -e \
" $([[ $i != ${#yzsearch[@]} ]]&&echo ├||echo ╰)"\
" $h02实例$h03[$((i + 1))] $h19${yzsearch[$i]}\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[M] $h09自述: $h04"\
"$(width=15;span_0=$((${#yz_m} / width));span_1=$(cll ${#yz_m} / ${width});[[ $span_1 > $span_0 ]]&&let span_0++;for ((i=0;i<${span_0};i++));do [[ ! $i = 0 ]]&&echo -ne " │      │           $h02[$i] "||echo -en "$h02[$i] ";echo -e "$h04${yz_m:$((i * width)):${width}}";done)\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[V] $h09版本号: $h04${yz_ver} [Version]\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[T] $h09更新日期: $h04$(echo ${yz_t}|sed 's/\//年/;s/\//月/;s/$/日/')\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[U] $h09修改日期: $h04${yz_l[5]} $(sed 's/:/时/;s/$/分/' <<< ${yz_l[6]}) [系统回报]\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[F] $h09函数: $h04$yz_f个 [Function]\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ├ $h02[S]$h09 解释器: $h04$yz_s $([[ $yz_s =~ sh$ ]]&&echo [Shell]||echo [Other])\n"\
" $([[ $i != ${#yzsearch[@]} ]]&&echo │||echo " ") "\
"     ╰ $h02[B] $h09大小: $h04$(printf %.2f $yz_k)KB [$yz_b]\n"\
" │"
done
echo -e \
" ╰ $h02总和$h03[A]$h19 All\n"\
"        ├ $h02[F] $h09函数: $h04$(printf %.0f $yz_all_f)个\n"\
"        ╰ $h02[B] $h09大小: $h04$(printf %.2f $yz_all_k)KB$h06"
) | less -Rm
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-v|*)
list_ver=$(setting versions $0)
tui_ver=$(setting versions $thetui)
api_ver=$(setting versions $theapi)
file_ver=$(setting versions $thefile)
lite_ver=$(setting versions $thelite)
echo -e "yunzai版本: ${versions}
yunzai-list版本: ${list_ver[0]}
yunzai-menu版本: ${tui_ver}
yunzai-api版本: ${api_ver}
yunzai-file版本: ${file_ver}
yunzai-lite版本: ${lite_ver}"
esac
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
x0x1x2x3x4x5x6x7x8x9)
if [ ! ${isbot} = true ];then
err "项目不存在，拒绝运行"
exit 1
fi
while true; do
if [ -f $defconfig ];then
watchdog=$(setting dog $defconfig)
else
watchdog=$(setting dog $0)
fi
   if [ $watchdog = true ];then
   if [[ $(ip a | grep inet | wc -l) = 2 ]];then
        echo
        err "检测到WALN已断开，尝试终止${name}的进程..."
        poss
        unset NODE_OPTIONS
        exit 127
    fi
  else
  warn "WatchDog检测状态更新，尝试回收进程..."
  unset NODE_OPTIONS
  exit 0
  fi
done
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
readme)
echo -e "$name $versions $times $indexURL $0 $theplugin $thetui"
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
r|-r|-rf|run|--run|-run|--run-function)
function=(`grep -o '^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*(){' $0 | tr -d '(){}'`)
function=($(for i in "${function[@]}"; do echo $i; done | sort))
if [ -z $2 ];then
echo -e "可供调用的函数有:\n${function[@]}\n共计[$h02${#function[@]}$h06]个函数，详见$h02 yunzai --run-function -hlep $h06"
exit 0
fi
if [[ $2 =~ ^(-h|--help|-help|help|h)$ ]];then
prev_letter=""
for ((i=0;i<${#function[@]};i++));do
_name_=${function[$i]}
current_letter=$(echo "$_name_" | awk '{print substr($1, 1, 1)}')
if [[ $current_letter =~ [a-zA-Z] ]]; then if [ "${current_letter^}" != "${prev_letter^}" ];then
[[ $i = 0 ]]&&echo -e \
"按[${h02}Q${h06}]键离开界面 按[${h02}↑${h06}][${h02}↓${h06}]键/鼠标滚轮/触屏上下滑动翻阅\n"\
"函数使用方法：yunzai run [函数名] [函数参数] ...\n"\
"部分函数为脚本内部使用而建立，而部分函数具有一定破坏性，请谨慎使用\n"\
" $h19## 共 $h16[${#function[@]}]$h19 个函数 ##\n"\
"$h02[@]$h06 可供调用的函数有:"
echo -e "$h16[${current_letter^}]──────────────────────────────────────────────────────────────────────\n $h06│";prev_letter="$current_letter";fi;else if [ -n "$prev_letter" ]; then echo -e "$h16[#]──────────────────────────────────────────────────────────────────────$h06\n │";prev_letter="";fi;fi
echo -e \
" $([[ $(($i + 1)) != ${#function[@]} ]]&&echo ├||echo └) $h03[$((i + 1))] $h04函数名$h06：$h19${function[$i]}\n"\
" $([[ $(($i + 1)) != ${#function[@]} ]]&&echo │||echo " ")$([ $(($i + 1)) -gt 9 ]&&echo " ")  └$h02[#]$h06"\
" $h09描述$h06:$h04"\
" $(grep -E "^${function[$i]}\(\)\{." $0 | sed 's/.*#%//')$h06\n $([[ $(($i + 1)) != ${#function[@]} ]]&&echo │||echo " ")"
done | less -Rm
exit 0
fi
j=0
for i in ${function[@]};do
if [[ $i == $2 ]];then
let j++
fi
done
if [[ $j == 1 ]];then
$2 "${@: 3}"
else
echo -e "yunzai: $2: 不是一个函数"
fi
;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-ih|ih|-hi|hi)yunzai -i -h;;
-iy|iy|-yi|yi)yunzai install -y ${@: 2};;
-il|il|-li|li)yunzai -i -l;;
-lj|-jl|lj|jl)yunzai -l js;;
-lp|-pl|lp|pl)yunzai -l plugin;;
-ic|ic|-ci|ci)yunzai -i -c ${@: 2};;
-im|im|-mi|mi)yunzai -i -m ${@: 2};;
-icy|icy|-ciy|ciy|-yic|yic|-iyc|iyc|-cyi|cyi)yunzai -i -c ${@: 2} -y;;
-imy|imy|-miy|miy|-yim|yim|-iym|iym|-myi|myi)yunzai -i -m -y ${@: 3};;
-ia|ia|-ai|ai)yunzai -i --add;;
-ib|ib|-bi|bi)yunzai -i --Bot $2;;
-rh|rh|-hr|hr|-rfh|rfh|-hrf|hrf|-rhf|rhf|-fhr|fhr)yunzai run -help;;
-vv)yunzai -v -vv;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-p|plugin|--plugin|--run-plugin)
[ -z $2 ]&&echo "用法: yunzai -p [插件名] [操作]"&&exit 0
yunzai-"${2}" "${@: 3}";;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
-P|--property)
(free=($(free | sed -n '2p'))
disk=($(df -lhPB1 | sed '1d' | sort | sed -n '1p'))
free1=$(cll ${free[3]}+${free[5]}-${free[4]}) #可用内存
free2=$(cll ${free[1]}-${free1}) #已用内存
free3=$(cll ${free[3]} / ${free[1]})
free4=$(cll 1-${free3}/${free[1]}) #物理内存占用率
free5=$(cll ${free2}/${free[1]}) #内存占用率
free6=$(cll ${free[1]}-${free[3]}) #物理已用内存
disk1=$(cll ${disk[2]}/${disk[1]}) #存储使用率
cpu1=($((LANG=en_US-UTF.8;lscpu) | grep "Model name" | sed 's/Model name://')) #处理器名称
cpu2=($((LANG=en_US-UTF.8;lscpu) | grep "CPU max" | sed 's/CPU.*\://')) #处理器最高频率（MHz）
cpu3=($((LANG=en_US-UTF.8;lscpu) | grep "CPU min" | sed 's/CPU.*\://')) #处理器最低频率（MHz）
cpu4=($((LANG=en_US-UTF.8;lscpu) | grep "Core(s) per socket" | sed 's/Core(s) per socket\://'))
cpu5=($((LANG=en_US-UTF.8;lscpu) | grep "Thread(s) per core" | sed 's/Thread(s) per core\://'))
echo -e "$h03[${h02}CPU$h03]───────────────────────────────────────"
for ((i=0;i<${#cpu1[@]};i++));do
echo -e "  $h03├ [$h02$((i + 1))$h03]$h16 处理器: $h19${cpu1[$i]}\n"\
"  $h03│  ├$h16 最高频率: $h19$(printf %.2f ${cpu2[$i]}) ${h15}MHz\n"\
"  $h03│  ├$h16 最低频率: $h19$(printf %.2f ${cpu3[$i]}) ${h15}MHz\n"\
"  $h03│  ├$h16 核心数: $h19${cpu4[$i]}\n"\
"  $h03│  ├$h16 超线程: $h19$([[ ${cpu5[$i]} = 1 ]]&&echo "否"||echo "是，每个核心$h18${cpu5[$i]}$h19个线程")\n"\
"  $h03│  ╰$h16 线程数: $h19$(cll ${cpu4[$i]}*${cpu5[$i]})\n  $h03│"
done
# 变量${free[N]} N对应的数字：
# 1: 物理装载的内存
# 2: 已使用的内存
# 3: 物理剩余的内存大小
# 4: 系统共享的内存
# 5: 系统缓存块
# 6: 应用层可用的内存
echo -e "$h03[${h02}RAM$h03]────────────────────────────────────────"
echo -e "  $h03├$h02 [S]\n$h03  │  ├$h16 制造商标称内存大小: "\
"$h19$(printf %.2f $(printf %.0f $(cll ${free[1]}/1000^2)))$h06$h15 GB $h18[1000]制\n"\
"  $h03│  ╰$h16 物理内存大小: $h06$h19$(printf %.2f $(cll ${free[1]}/1024^2))$h06$h15 GB $h18[1024]制\n  $h03│\n"\
"  $h03├ [${h02}US$h03]\n  $h03│  ├ [$h02系统回报$h03]$h16 可用内存: $h19$(printf %.2f $(cll ${free1}/1024^2))$h15 GB\n"\
"  $h03│  ├ [$h02系统回报$h03]$h16 已用内存: $h19$(printf %.2f $(cll ${free2}/1024^2))$h15 GB\n"\
"  $h03│  ╰ [$h02系统回报$h03]$h16 内存占用率: $h19$(printf %.2f $(cll ${free5}*100))$h06$h15 %\n  $h03│\n"\
"  $h03├ [${h02}EH$h03]\n  $h03│  ├$h16 物理可用内存: $h06$h19$(printf %.2f $(cll ${free[3]}/1024^2))$h15 GB\n"\
"  $h03│  ├$h16 物理已用内存: $h06$h19$(printf %.2f $(cll ${free6}/1024^2))$h15 GB\n"\
"  $h03│  ╰$h16 物理内存占用率: $h06$h19$(printf %.2f $(cll ${free4}*100))$h15 %\n"\
"  $h03│\n$h03[${h02}ROM$h03]────────────────────────────────────────\n"\
"  $h03╰ [${h02}D$h03]\n     $h03├$h16 制造商标称存储大小: $h19$(printf %.2f $(printf %.0f $(cll ${disk[1]}/968^3)))$h15 GB $h18[1000]制\n  $h03   ├$h16 物理存储大小:$h19 $(printf %.2f $(cll ${disk[1]}/1024^3))$h15 GB $h18[1024]制\n"\
"     $h03├$h16 已使用的存储: $h19$(printf %.2f $(cll ${disk[2]}/1024^3))$h15 GB\n"\
"     $h03├$h16 剩余存储大小: $h19$(printf %.2f $(cll ${disk[3]}/1024^3))$h15 GB\n"\
"     $h03╰$h16 物理存储占用率: $h19$(printf %.2f $(cll ${disk1}*100))$h15 %"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
[ ! -z $(command -v getprop) ]&&echo -e \
"\n$h03[${h02}INFO$h03]───────────────────────────────────────\n"\
"  $h03╰ [EQ]\n"\
"     $h03├ [$h02区域语言$h03] $h16$(getprop ro.product.locale)\n"\
"     $h03├ [$h02设备代号$h03] $h16$(getprop ro.product.device)\n"\
"     $h03├ [$h02设备型号$h03] $h16$(getprop ro.product.model)\n"\
"     $h03├ [$h02设备品牌$h03] $h16$(getprop ro.product.brand)\n"\
"     $h03├ [$h02设备制造商$h03] $h16$(getprop ro.product.manufacturer)\n"\
"     $h03├ [$h02设备名称$h03] $h16$(getprop ro.product.name)\n"\
"     $h03├ [$h02主板平台$h03] $h16$(getprop ro.board.platform)\n"\
"     $h03├ [$h02处理器型号$h03] $h16$(getprop ro.hardware)\n"\
"     $h03├ [$h02处理器版本$h03] $h16$(getprop ro.product.cpu.abi)\n"\
"     $h03├ [$h02处理器兼容的版本$h03]\n   $h03  │            [${h02}V$h03] ╯\n    $h03 │             ├ $h16$(getprop ro.product.cpu.abilist|sed "s/\,/\n    \\\033[36m │             ├ \\\033[1\;33m/g"|sed '$s/├/╰/')\n"\
"     $h03├ [$h02安卓版本$h03] $h16$(getprop ro.build.version.release)"\
              "$h06$h03(${h18}SDK $h19$(getprop ro.build.version.sdk)$h06$h03)\n"\
"     $h03├ [$h02系统版本$h03] $h16$(getprop ro.build.version.incremental)\n"\
"     $h03│          ╰ $h16$(getprop ro.build.display.id)\n"\
"     $h03├ [$h02编译时间$h03] $h16$(date -d "@$(getprop ro.build.date.utc)" "+%F %T")\n"\
"     $h03╰ [$h02基带版本$h03] $h16$(getprop gsm.version.baseband|cut -d "," -f1)"
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
if [ ${free1} -lt 307200 ];then
echo -e "\n$h03[${h04}WARN$h03]────────────────────────────────────────\n$h04内存吃紧 $h02[系统回报的剩余内存低于${h01}300${h06}${h04}MB$h02]\n$h02建议$h01重启设备"
fi) | less -R;;
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
*)
err "yunzai: $1: 未知的选项"
esac
fi